home *** CD-ROM | disk | FTP | other *** search
/ MacFormat España 19 / macformat_19.iso / Shareware / Games / Star Flick / CT / Source / GameSounds.c < prev    next >
Text File  |  1994-03-10  |  2KB  |  73 lines

  1. /************************************************************************************
  2.  * GameSounds.c
  3.  *
  4.  * CheeseToast by Jim Bumgardner
  5.  *
  6.  * Note: When startup sound is played, I'm getting an audio glitch
  7.  * if sound manager 3.0 is installed.
  8.  ************************************************************************************/
  9.  
  10. #include "CToast.h"
  11. #include <Sound.h>
  12.  
  13. static Handle            sounds[S_NbrSounds];
  14. static SndChannelPtr    scp;
  15. static SndCommand        tCmd;                        /* Sound Command */
  16. static short            savedVolume;
  17.  
  18. pascal void MyCallBack(SndChannelPtr chan, SndCommand *cmd)
  19. {
  20.     chan->userInfo = 0;
  21. }
  22.  
  23. void InitSounds()
  24. {
  25.     short    i;
  26.     OSErr    oe;
  27.     for (i = 0; i < S_NbrSounds; ++i) {
  28.         sounds[i] = Get1Resource('snd ',128+i);
  29.         if (sounds[i] != NULL) {
  30.             HNoPurge(sounds[i]);
  31.             MoveHHi(sounds[i]);
  32.             HLock(sounds[i]);
  33.         }
  34.     }
  35.     scp = (SndChannelPtr) NewPtrClear((long) sizeof(SndChannel));
  36.     scp->qLength = stdQLength;
  37.     if ((oe = SndNewChannel(&scp,sampledSynth,initMono,(ProcPtr) MyCallBack)) != noErr)
  38.         DebugStr("\pSound Problem");
  39.  
  40.     GetSoundVol(&savedVolume);
  41.     SetSoundVol(gPrefs.soundLevel);
  42. }
  43.  
  44. void EndSounds()
  45. {
  46.     if (scp) {
  47.         SndDisposeChannel(scp,true);
  48.         DisposPtr((Ptr) scp);
  49.         scp = 0L;
  50.     }
  51.     SetSoundVol(savedVolume);
  52. }
  53.  
  54. void PlaySound(short i, short priority)
  55. {
  56.     if (gPrefs.soundLevel > 0 && i < S_NbrSounds && sounds[i] &&
  57.         priority > scp->userInfo) {
  58.         tCmd.cmd = quietCmd;
  59.         SndDoImmediate(scp,&tCmd);
  60.         tCmd.cmd = flushCmd;
  61.         SndDoImmediate(scp,&tCmd);
  62.         SndPlay(scp, sounds[i], true);
  63.         scp->userInfo = priority;
  64.         tCmd.cmd = callBackCmd;
  65.         SndDoCommand(scp,&tCmd,true);
  66.     }
  67.     if (sounds[S_Startup] != NULL && i != S_Startup) {
  68.         DisposeHandle(sounds[S_Startup]);
  69.         sounds[S_Startup] = NULL;
  70.     }
  71. }
  72.  
  73.